<?php 
$this->load->view('admin/layout/head', array('title'=>'题目管理'), FALSE);
?>

<div id="container">
	<form class="form-inline" id="search-form" method="GET" action="/admin/question">
	  <div class="form-group">
	  	<select name="type" class="form-control">
	  		<option value="">题型</option>
	  		<?php foreach($question_types as $k=>$v): ?>
	  		<option value="<?php echo $k?>"><?php echo $v ?></option>
	  		<?php endforeach; ?>
	  	</select>
	  </div>
	  <div class="form-group">
	  	<select name="score" class="form-control">
	  		<option value="">题目分数</option>
	  		<?php for ($i=1; $i <8 ; $i++) { 
	  		echo '<option value="'.$i.'">'.$i.'分</option>';
	  		} ?>
	  	</select>
	  </div>
	  <?php foreach ($question_attr as $key => $attr): ?>
	  <div class="form-group">
	  	<select name="<?php echo $key ?>" class="form-control" style="max-width: 160px;">
	  		<option value=""><?php echo $key ?></option>
	  		<?php foreach($attr as $k=>$v): ?>
	  		<?php if(is_array($v)): ?>
	  			<optgroup label="<?php echo $k ?>">
	  			<?php foreach($v as $k1=>$v1): ?>
	  				<option value="<?php echo $k1?>"><?php echo $v1 ?></option>
	  			<?php endforeach; ?>
	  			</optgroup>
	  		<?php else: ?>
	  		<option value="<?php echo $k?>"><?php echo $v ?></option>
	  		<?php endif; ?>
	  		<?php endforeach; ?>
	  	</select>
	  </div>
	  <?php endforeach; ?>

	  
	  <div class="form-group">	   
	    <input type="text" name="keyword" class="form-control" style="width:300px" placeholder="">
	  </div>
	  <a href="javascript:;" class="btn btn-info search-btn">搜索</a>
	  <a href="/admin/question/add" class="btn btn-default add-btn"><span class="glyphicon glyphicon-plus"></span> 添加题目</a>
	</form>
	<div class="table-container mt-10">
		<table class="table table-bordered table-striped table-hover scroll-table">
			<thead >
				<tr>
					<th width="140" class="text-center">题目信息</th>
					<th width="200" class="text-center">题干</th>
					<th width="200" class="text-center">选项</th>
					<!-- <th width="200" class="text-center">解析</th> -->
					<th width="200" class="text-center">题目属性</th>
					<th width="100" class="text-center">正确率</th>
					<th width="80" class="text-center">操作</th>
				</tr>
			</thead>
			<tbody class="text-center">
				<?php foreach($questions as $q): ?>
				<tr id='tr-<?php echo $q['id']?>'>
					<td class="text-left">
						题目编号：<?php echo $q['id']?><br>
						题目类型：<?php echo $question_types[$q['type']]?><br>
						题目分值：<?php echo $q['score']?>分
					</td>
					<td class="text-left"><?php echo $q['content'] ?></td>
					<td class="text-left">
						<?php echo Models\Question::options_display($q['type'],$q['options'],$q['answer']) ?>
						<?php //echo $q['options'] ?>
					</td>
					<!-- <td class="text-left">
						<div><?php echo $q['rationale'] ?></div>
						<div><?php echo $q['strategy'] ?></div>
					</td> -->
					<td class="text-left">
						<?php echo $question_attr['cognitive_ability'][$q['cognitive_ability']] ?><br>
						<?php echo $question_attr['client_needs'][$q['client_needs']] ?><br>
						<?php echo $question_attr['nursing_process'][$q['nursing_process']] ?><br>
						<?php 

						foreach ($question_attr['content_area'] as $key => $value) {
							foreach ($value as $k => $v) {
								if($k == $q['content_area']){
									echo '['.$key.']'.$v;
									break;
								}
							}
						}
						//echo $question_attr['content_area'][$q['content_area']] ?>
					</td>
					<td class="text-left">
						总做题数：<?php echo $q['total']?><br>
						正确数量：<?php echo $q['correct']?><br>
						正确比例：<?php echo $q['total']?round($q['correct']/$q['total']*100).'%':'-'?>
					</td>
					<td>
						<a href="/admin/question/edit/<?php echo $q['id'] ?>" class="modify-btn">查看</a><br> 
						<a href="javascript:;" class="del-btn" question_id="<?php echo $q['id'] ?>">删除</a>			
					</td>
				</tr>
				<?php endforeach; ?>
			</tbody>
			<?php 
			if($questions->last_page>1){
			?>
			<tfoot>
				<td colspan="6" style="text-align:right">
					<?php echo $questions->render() ?>
				</td>
			</tfoot>
			<?php 
			}
			?>
		</table>
	</div>
</div>


<?php 
$this->load->view('admin/layout/footer');
?>

<script type="text/javascript">
	$(function(){
		$('.del-btn').on('click',function(){
			var question_id = $(this).attr('question_id');
			confirm('确定要删除此题目吗？',function(e){
				if(e.index == 1){
					Toast.loading();
					$.post('/admin/question/delete', {id: question_id}, function(data, textStatus, xhr) {
						Toast.destory();
						Toast.success('删除成功',function(){
							window.location.reload();
						})
					});
				}
			})
		});

		$('.search-btn').on('click',function(){
			$('#search-form').submit();
		})

		var hash = window.location.hash;
		if(hash){
			$(hash).css('background-color','#ccc');
		}
	})
</script>















